package pers.tz.题目.排序;

import static pers.tz.common.SortUtils.*;

/**
 * @author irony
 * @date 2024-03-09
 */
public class 选择排序 {

    public static void main(String[] args) {
        int[] ints = generateRandomArray(100000);
        printArrayTime(() -> selectSort(ints), ints, false);
    }

    /**
     * 选择排序，降序
     *
     * @param ints
     */
    private static void selectSort(int[] ints) {
        for (int i = 0; i < ints.length; i++) {
            int minIndex = i;
            for (int j = i + 1; j < ints.length; j++) {
                if (ints[j] < ints[minIndex]) {
                    minIndex = j;
                }
            }
            int temp = ints[i];
            ints[i] = ints[minIndex];
            ints[minIndex] = temp;
        }
    }

}
